package com.th.supcom.pds.impl.service.internal;

import java.util.List;
import java.util.Map;

import net.carefx.framework.exception.BusinessException;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.th.supcom.pds.domain.pojo.PdsPrescDispenseWindow;
import com.th.supcom.pds.domain.pojo.PdsSupplyPro;
import com.th.supcom.pds.domain.vo.PdsSupplyDetailVO;
import com.th.supcom.pds.impl.manager.PdsSupplyProManager;
import com.th.supcom.pds.internal.api.PdsSupplyProService;

/* $Id$
 *
 * Copyright ( c ) 2014 XuNuo Corporation. All Rights Reserved.
 *
 * This software is the confidential and proprietary information of XuNuo
 * Corporation ("Confidential Information").  You shall not disclose such
 * Confidential Information and shall use it only in accordance with the terms
 * of the license agreement you entered into with XuNuo Corporation or a XuNuo
 * authorized reseller (the "License Agreement"). XuNuo may make changes to the
 * Confidential Information from time to time. Such Confidential Information may
 * contain errors.
 *
 * EXCEPT AS EXPLICITLY SET FORTH IN THE LICENSE AGREEMENT, XuNuo DISCLAIMS ALL
 * WARRANTIES, COVENANTS, REPRESENTATIONS, INDEMNITIES, AND GUARANTEES WITH
 * RESPECT TO SOFTWARE AND DOCUMENTATION, WHETHER EXPRESS OR IMPLIED, WRITTEN OR
 * ORAL, STATUTORY OR OTHERWISE INCLUDING, WITHOUT LIMITATION, THE IMPLIED
 * WARRANTIES OF MERCHANTABILITY, TITLE, NON-INFRINGEMENT AND FITNESS FOR A
 * PARTICULAR PURPOSE. XuNuo DOES NOT WARRANT THAT END USER'S USE OF THE
 * SOFTWARE WILL BE UNINTERRUPTED, ERROR FREE OR SECURE.
 *
 * XuNuo SHALL NOT BE LIABLE TO END USER, OR ANY OTHER PERSON, CORPORATION OR
 * ENTITY FOR INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL
 * DAMAGES, OR DAMAGES FOR LOSS OF PROFITS, REVENUE, DATA OR USE, WHETHER IN AN
 * ACTION IN CONTRACT, TORT OR OTHERWISE, EVEN IF XuNuo HAS BEEN ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGES. XuNuo' TOTAL LIABILITY TO END USER SHALL NOT
 * EXCEED THE AMOUNTS PAID FOR THE XuNuo SOFTWARE BY END USER DURING THE PRIOR
 * TWELVE (12) MONTHS FROM THE DATE IN WHICH THE CLAIM AROSE.  BECAUSE SOME
 * STATES OR JURISDICTIONS DO NOT ALLOW LIMITATION OR EXCLUSION OF CONSEQUENTIAL
 * OR INCIDENTAL DAMAGES, THE ABOVE LIMITATION MAY NOT APPLY TO END USER.
 *
 * Copyright version 2.0
 */
/**
 * 处方过程服务
 */
public class PdsSupplyProServiceImpl implements PdsSupplyProService
{

    private PdsSupplyProManager m_pdsSupplyProManager;

    public void setPdsSupplyProManager (PdsSupplyProManager pdsSupplyProManager)
    {

        this.m_pdsSupplyProManager = pdsSupplyProManager;
    }

    /**
     * 供药过程持久化
     */
    @Override
    public void persistentPdsSupplyPro (PdsSupplyPro pdsSupplyPro)
    {
        s_logger.info ("调用persistentPdsSupplyPro供药过程持久化,入参:{}", new Object[]
        { pdsSupplyPro });
        try
        {
            m_pdsSupplyProManager.addPdsSupplyPro (pdsSupplyPro);
        }
        catch (Exception e)
        {
            s_logger.error ("处方持久化异常！异常信息：", new Object[]
            { e });
            throw new BusinessException ("数据库插入出现异常" + e.getMessage (), e);
        }

    }

    @Override
    public void modifyPdsSupplyProByExample (PdsSupplyPro pdsSupplyPro)
    {
        s_logger.debug ("进入modifyPdsSupplyProByExample方法,入参:{}", new Object[]
        { pdsSupplyPro });
        try
        {
            m_pdsSupplyProManager.modifyPdsSupplyProByExample (pdsSupplyPro);
        }
        catch (Exception e)
        {
            s_logger.error (e.getLocalizedMessage ());
            throw new BusinessException ("数据库更新出现异常,前联系计算机中心");
        }

    }

    /** 日志记录器. */
    public static final Logger s_logger = LoggerFactory.getLogger (PdsSupplyProServiceImpl.class);

    /** 公司版权信息. */
    public static final String copyright = "Copyright 2014, XuNuo Corporation";

    /** 提交路径. */
    public static final String SCC_BRANCH = "$URL$";

    /** 提交日期. */
    public static final String SCC_LAST_MODIFICATION_DATE = "$Date$";

    /** 最终修改人员. */
    public static final String SCC_LAST_MODIFIER_NAME = "$Author$";

    /** 最终版本号. */
    public static final String SCC_REVISION = "$Revision$";

    @Override
    public void modifyPdsSupplyProWindow (List <PdsSupplyDetailVO> list, Long window)
    {
        if (list.isEmpty ())
        {
            throw new BusinessException ("集合为空");
        }
        for (PdsSupplyDetailVO detail : list)
        {
            PdsSupplyPro pro = new PdsSupplyPro ();
            pro.setId (detail.getProId ());
            pro.setOutpDispensaryWin (window + "");
            modifyPdsSupplyProByExample (pro);
        }
    }

    @Override
    public List <PdsSupplyPro> findPdsSupplyProByExample (PdsSupplyPro pdsSupplyPro)
    {
        List <PdsSupplyPro> list = null;
        try
        {
            // 判断是否已经存在
            list = m_pdsSupplyProManager.findPdsSupplyProListByExample (pdsSupplyPro);
        }
        catch (Exception e)
        {
            s_logger.error (e.getMessage ());
            throw new BusinessException ("数据库查询出现异常" + e.getMessage (), e);
        }

        return list;
    }

    @Override
    public int modifyPdsSupplyProSortInfoByList (List <PdsSupplyPro> pdsSupplyPros)
    {
        s_logger.debug ("modifyPdsSupplyProSortInfoByList方法");
        try
        {
            return m_pdsSupplyProManager.modifyPdsSupplyProSortInfoByList (pdsSupplyPros);
        }
        catch (Exception e)
        {
            s_logger.error (e.getLocalizedMessage ());
            throw new BusinessException ("数据库更新出现异常,前联系计算机中心");
        }
    }

    @Override
    public List <PdsPrescDispenseWindow> findPdsPrescWindowByMap (Map <String, Object> params)
    {
        try
        {
            return m_pdsSupplyProManager.findPdsPrescWindowByMap (params);
        }
        catch (Exception e)
        {
            s_logger.error (e.getLocalizedMessage ());
            throw new BusinessException ("数据库查询出现异常,前联系计算机中心");
        }

    }

    @Override
    public void modifyBatchSupplyWindow (Map <String, Object> map)
    {

        s_logger.debug ("结束modifyBatchSupplyWindow方法.");
        try
        {
            m_pdsSupplyProManager.modifyBatchSupplyWindow (map);
        }
        catch (Exception e)
        {
            s_logger.error (e.getLocalizedMessage ());
            throw new BusinessException ("更新窗口出现异常,前联系计算机中心");
        }
    }

}
